package com.sojoys.artifact.factory.template;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Map;

import freemarker.template.Template;
import freemarker.template.TemplateException;


/**
 * @author : DengYing
 * @CreateDate : 2017年7月6日 上午11:12:22
 * @Description ：Please describe this document
 */
@SuppressWarnings("rawtypes")
public class FreemarkerTemplate extends ITemplate<Template> {

	
	public FreemarkerTemplate(Template template) {
		super();
		t = template;
	}

	@Override
	public String render(Map map) {
		StringWriter sw = new StringWriter();
		renderTo(map,sw);
		return sw.toString();
	}

	@Override
	public void renderTo(Map map,Writer writer) {
		try {
			t.process(map,writer);
		} catch (TemplateException | IOException e) {
			e.printStackTrace();
		}
	}
}
